package cn.iocoder.yudao.module.polling.controller.admin.pollingcategoriesrelevance;

import cn.iocoder.yudao.module.polling.controller.admin.pollingcategoriesrelevance.vo.*;
import cn.iocoder.yudao.module.polling.convert.pollingcategoriesrelevance.PollingCategoriesRelevanceConvert;
import cn.iocoder.yudao.module.polling.dal.dataobject.pollingcategoriesrelevance.PollingCategoriesRelevanceDO;
import cn.iocoder.yudao.module.polling.service.pollingcategoriesrelevance.PollingCategoriesRelevanceService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;


@Api(tags = "管理后台 - 巡检标准适用类别关联")
@RestController
@RequestMapping("/abu/polling-categories-relevance")
@Validated
public class PollingCategoriesRelevanceController {

    @Resource
    private PollingCategoriesRelevanceService pollingCategoriesRelevanceService;

    @PostMapping("/create")
    @ApiOperation("创建巡检标准适用类别关联")
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:create')")
    public CommonResult<Integer> createPollingCategoriesRelevance(@Valid @RequestBody PollingCategoriesRelevanceCreateReqVO createReqVO) {
        return success(pollingCategoriesRelevanceService.createPollingCategoriesRelevance(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新巡检标准适用类别关联")
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:update')")
    public CommonResult<Boolean> updatePollingCategoriesRelevance(@Valid @RequestBody PollingCategoriesRelevanceUpdateReqVO updateReqVO) {
        pollingCategoriesRelevanceService.updatePollingCategoriesRelevance(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除巡检标准适用类别关联")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:delete')")
    public CommonResult<Boolean> deletePollingCategoriesRelevance(@RequestParam("id") Integer id) {
        pollingCategoriesRelevanceService.deletePollingCategoriesRelevance(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得巡检标准适用类别关联")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:query')")
    public CommonResult<PollingCategoriesRelevanceRespVO> getPollingCategoriesRelevance(@RequestParam("id") Integer id) {
        PollingCategoriesRelevanceDO pollingCategoriesRelevance = pollingCategoriesRelevanceService.getPollingCategoriesRelevance(id);
        return success(PollingCategoriesRelevanceConvert.INSTANCE.convert(pollingCategoriesRelevance));
    }

    @GetMapping("/list")
    @ApiOperation("获得巡检标准适用类别关联列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:query')")
    public CommonResult<List<PollingCategoriesRelevanceRespVO>> getPollingCategoriesRelevanceList(@RequestParam("ids") Collection<Integer> ids) {
        List<PollingCategoriesRelevanceDO> list = pollingCategoriesRelevanceService.getPollingCategoriesRelevanceList(ids);
        return success(PollingCategoriesRelevanceConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得巡检标准适用类别关联分页")
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:query')")
    public CommonResult<PageResult<PollingCategoriesRelevanceRespVO>> getPollingCategoriesRelevancePage(@Valid PollingCategoriesRelevancePageReqVO pageVO) {
        PageResult<PollingCategoriesRelevanceDO> pageResult = pollingCategoriesRelevanceService.getPollingCategoriesRelevancePage(pageVO);
        return success(PollingCategoriesRelevanceConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出巡检标准适用类别关联 Excel")
    @PreAuthorize("@ss.hasPermission('abu:polling-categories-relevance:export')")
    @OperateLog(type = EXPORT)
    public void exportPollingCategoriesRelevanceExcel(@Valid PollingCategoriesRelevanceExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<PollingCategoriesRelevanceDO> list = pollingCategoriesRelevanceService.getPollingCategoriesRelevanceList(exportReqVO);
        // 导出 Excel
        List<PollingCategoriesRelevanceExcelVO> datas = PollingCategoriesRelevanceConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "巡检标准适用类别关联.xls", "数据", PollingCategoriesRelevanceExcelVO.class, datas);
    }

}
